#pragma once


#include "Socket.h"
#include "Channel.h"


class EventLoop;
class InetAddress;

class Acceptor : noncopyable
{
public:
    using NewConnectionCallback = std::function<void(int sockfd, const InetAddress&)>;

    Acceptor(EventLoop* loop, const InetAddress& listenAddr, bool reuseprot);
    ~Acceptor();

    void setNewConnectionCallback(const NewConnectionCallback& cb)
    {
        m_newConnectionCallback = cb;
    }

    bool listening() const { return m_listening; }
    void listen();

private:
    void handleRead();

private:
    // Acceptor所在的loop就是用户定义的那个mainloop
    EventLoop* m_loop;
    Socket m_acceptSocket;
    Channel m_acceptChannel;
    NewConnectionCallback m_newConnectionCallback;
    bool m_listening;
};